<template>
	<w-container class="plr-16">
		<w-navbar :title="type == 1?'系统消息':'平台消息'" bgColor="#fff"></w-navbar>
		<view v-for="(item,index) in list" :key="item.id" class="flex flex-dir-col flex-ai-center">
			<view class="font-color-666 mt-16">{{ item.createtime }}</view>
			<view class="bg-color-white br-8 mt-12 pa-12 w-100">
				<view class="font-w-500">{{ item.title }}</view>
				<view class="mt-8 font-color-999 font-size-12">
					{{ item.content }}
				</view>
			</view>
		</view>
		<w-loading style="padding: 32rpx 0" :type="loadingType" emptyType="search" emptyTop="60"></w-loading>
	</w-container>
</template>

<script>
	import {
		newList
	} from "@/api/collection/index.js";
	export default {
		data() {
			return {
				type:1,
				loadingType:'none',
				page:1,
				list:[]
			}
		},
		onLoad({type = 1}){
			this.type = type
			this.getList()
		},
		onPullDownRefresh() {
			this.loadingType = 'none'
			this.page = 1
			this.list = []
			this.getList()
		},
		onReachBottom() {
			if(this.loadingType == 'nomore') return
			this.page++
			this.getList()
		},
		methods: {
			async getList(){
				this.loadingType = 'loading'
				if(this.type == 2) {			
					setTimeout(() => {
						 this.loadingType = 'empty'
						 uni.stopPullDownRefresh()
					},1500)
					return
				}
				const { data,code } = await newList({
					page:this.page
				})
				uni.stopPullDownRefresh()
				if(code != 1) return
				if(this.page == 1 && data.list.length == 0) return this.loadingType = 'empty'
				this.list = this.list.concat(data.list)
				if(data.list.length == 0) this.loadingType = 'nomore'
			}
		}
	}
</script>

<style>

</style>
